package com.example.androidexample.interpolater;

import android.os.Bundle;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AnticipateInterpolator;
import android.view.animation.AnticipateOvershootInterpolator;
import android.view.animation.BounceInterpolator;
import android.view.animation.CycleInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.OvershootInterpolator;
import android.widget.RadioGroup;

import androidx.annotation.Nullable;

import com.example.androidexample.R;
import com.example.basic.base.BaseActivity;

/**
 * 需要看出效果  需要线形图  所以 需要先实现线形图功能
 */
public class InterpolaterActivity extends BaseActivity implements RadioGroup.OnCheckedChangeListener {

    private RadioGroup mInterpolatorGroup;
    private InterpolatorEffectDisplayView interpolater;

    @Override
    protected void initOnCreate(@Nullable Bundle savedInstanceState) {

        mInterpolatorGroup = findViewById(R.id.interpolator_group);
        mInterpolatorGroup.setOnCheckedChangeListener(this);

        interpolater = findViewById(R.id.interpolater);
        interpolater.setInterpolator(new AccelerateDecelerateInterpolator());
//        interpolater.setInterpolator(new AccelerateInterpolator());
//        interpolater.setInterpolator(new DecelerateInterpolator());
//        interpolater.setInterpolator(new LinearInterpolator());
//        interpolater.setInterpolator(new BounceInterpolator());
    }

    @Override
    protected int setLayoutXmlid() {
        return R.layout.activity_interpolater;
    }

    @Override
    public String getTag() {
        return "InterpolaterActivity";
    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.accelerate_decelerate:{
                interpolater.setInterpolator(new AccelerateDecelerateInterpolator());
            } break;
            case R.id.accelerate:{
                interpolater.setInterpolator(new AccelerateInterpolator());
            } break;
            case R.id.decelerate:{
                interpolater.setInterpolator(new DecelerateInterpolator());
            } break;
            case R.id.linear:{
                interpolater.setInterpolator(new LinearInterpolator());
            } break;
            case R.id.bounce:{
                interpolater.setInterpolator(new BounceInterpolator());
            } break;
            case R.id.anticipate:{
                interpolater.setInterpolator(new AnticipateInterpolator());
            } break;
            case R.id.overshoot:{
                interpolater.setInterpolator(new OvershootInterpolator());
            } break;
            case R.id.anticipate_overshoot:{
                interpolater.setInterpolator(new AnticipateOvershootInterpolator());
            } break;
            case R.id.cycle:{
                interpolater.setInterpolator(new CycleInterpolator(2));
            } break;
        }

    }
}
